Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New optional column: item_subtype #1143

Merged
merged 3 commits into from
Aug 27, 2018
Merged

New optional column: item_subtype #1143

merged 3 commits into from
Aug 27, 2018

Conversation

jaredbeck
Copy link
Member

@jaredbeck jaredbeck commented Aug 22, 2018

Gives PT-AT the data it needs to fix #594. PT-AT will make changes like:

# paper_trail_association_tracking/reifiers/has_one.rb
# def load_versions(assoc, model, transaction_id, version_at, base_class_name)
            where("#{version_table_name}.item_type = ?", base_class_name).
+           where("#{version_table_name}.item_subtype = ?", assoc.class_name).
            where("created_at >= ? OR transaction_id = ?", version_at, transaction_id).

I have tested the above with the "cars and bicycles" example in person_spec.rb and it passes.

Replaces (reverts) #1108, which has proved problematic in #1135, leading to further proposed increases in complexity such as seanlinsley#1. @lorint I know you worked hard on #1108, and I did too, but if this is actually the simpler approach, as I propose, I hope we can both approach this objectively. I've never had to revert something as large as #1108 and I don't suggest it lightly.

I haven't written the docs or the migration to populate item_subtype. I would like to get your opinions on this approach first.

I made this an optional column because it is my understanding that this issue (#594) only affects PT-AT users with STI, a very small subset of our users.

This partially reverts commit 58369e1.
I have kept the specs, skipped.

Per the following, this approach does not seem to be working:

- #1135
- #1137
- seanlinsley#1
If present, will be populated with subclass name. This will be
used by PT-AT.
Copy link
Contributor

@lorint lorint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a generator similar to update_sti that fills in item_subtype for historic records.

}
}
}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well at least keep this enhancement to the spec!

@@ -5,10 +5,8 @@
# The `Person` model:
#
# - has a dozen associations of various types
# - has a custom serializer, TimeZoneSerializer, for its `time_zone` attribute
# - has a custome serializer, TimeZoneSerializer, for its `time_zone` attribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo

@lorint
Copy link
Contributor

lorint commented Aug 22, 2018

If you're committed to going in this direction then it might be somewhat moot at this point, but I've pushed an update to Sean's PR#1 based on your review.

@jaredbeck
Copy link
Member Author

  1. Lorin, it sounds like you agree that this will give PT-AT the data it needs to solve Reify on associations fails if using Single Table Inheritance #594. Is that correct?
  2. Sean, can you test your app against this branch? I assume that, because I've reverted Fix for issue #594, reifying sub-classed models that use STI #1108, that this branch fixes your issue Unable to join versions association #1135.

@seanlinsley
Copy link
Member

I'll test this as soon as I can, but in the meantime these tests should verify the behavior if you'd like to add them to this PR:

@seanlinsley
Copy link
Member

This PR fixes both issues 🙌

@jaredbeck
Copy link
Member Author

.. in the meantime these tests should verify the behavior if you'd like to add them ..

Tests added.

Copy link
Member

@seanlinsley seanlinsley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the most maintainable fix for #594 since it doesn't require patching Rails. @lorint what do you think about the approach in general? (save from it not having a migration generator)

BTW the test failures can be fixed by adding group(:id)

@seanlinsley
Copy link
Member

We're now using this branch in production & will likely remove our object column next week.

Thank you both for all the time you've put into the upcoming release 💛

@jaredbeck
Copy link
Member Author

@lorint does this work for you? Does it provide PT-AT with the data it needs to solve #594? Please let me know if you have any objections. If I don't hear from you, I'll probably merge this weekend.

@lorint
Copy link
Contributor

lorint commented Aug 26, 2018

It does have the data we would need, and potentially covers Rick Tyler's interest around the store_base_sti_class gem.

It does require a fair bit of rework internally, doing checks around item_type and item_subtype. And around 16GB of additional storage requirement for this new column. But this will get offset by the possible removal of the object column in the near future.

We are considering both removing object and implementing the item_type code from PR#1137, in which case we could backport our fixes that use item_type for reification to PT-AT using item_subtype.

@jaredbeck
Copy link
Member Author

It does have the data we would need, and potentially covers Rick Tyler's interest around the store_base_sti_class gem.

Great, thanks.

And around 16GB of additional storage requirement for this new column.

If y'all are concerned about disk space, we could choose to store item_subtype only when it differs from item_type.

@jaredbeck jaredbeck merged commit 0db05a2 into master Aug 27, 2018
@jaredbeck
Copy link
Member Author

We're now using this branch in production.

I usually delete topic branches immediately after merging, so please switch to master ASAP.

@lorint
Copy link
Contributor

lorint commented Aug 27, 2018

If y'all are concerned about disk space, we could choose to store item_subtype only when it differs from item_type.

For us the disk space is of interest only in light of how far-reaching it is to have a half billion records loaded into RAM at once. We've got 5 covering indexes that leverage item_type, and there's some right magic we're able to unfold for our end users based on this, 2 of these 5 b-tree indexes have item_type as their primary index. Hence any even slight update to behaviour around item_type can mean significant impact on a fair range of tests, and around the amount of work the database engine goes through overall. No worries about extra overhead during CUD operations. Entire focus is on finding related transactions quickly. For us in these indexes we will continue to store real class names as opposed to base_class so we can have just one column involved, and maintain consistent sub-second searches on item_type.

@jaredbeck
Copy link
Member Author

For us the disk space is of interest only in light of how far-reaching it is to have a half billion records loaded into RAM at once.

Dang. And I thought Sean has a lot of records 😅

.. 2 of these 5 b-tree indexes have item_type as their primary index ..

db indexing practices are a personal interest of mine. I'd love to hear more about the shape of the queries and brainstorm about your index design. If it's not private IP, feel free to email me and we can chat more about about it.

aried3r pushed a commit to aried3r/paper_trail that referenced this pull request Dec 14, 2020
aried3r pushed a commit to aried3r/paper_trail that referenced this pull request Dec 14, 2020
hosamaly added a commit to hosamaly/paper_trail that referenced this pull request Feb 21, 2021
v10.0.0

* tag 'v10.0.0': (40 commits)
  Release 10.0.0
  Testing the :skip option
  allow `object_changes_adapter` to use the default behavior
  Lint: Improve Metrics/AbcSize from 22 to 21
  Docs: which class attributes are public/private
  Docs: installation
  Docs: Update changelog and readme re: paper-trail-gem#1143
  Generator to update historic item_subtype entries (paper-trail-gem#1144)
  Testing joins, as recommended by Sean
  Add optional column: item_subtype
  Revert paper-trail-gem#1108 (lorint's STI fix)
  Lint: RSpec/EmptyLineAfterExampleGroup
  Update development dependencies
  Lint: RSpec/InstanceVariable in model_spec, ctn'd
  Code style re: errors
  Docs: Fix link to bug report
  Add association tracking removal exception
  Readme fix: caller.find {} rather than caller.first {}
  Do not require PT-AT
  Docs: Organizing the changelog for 10.0.0
  ...
hosamaly added a commit to hosamaly/paper_trail that referenced this pull request Feb 21, 2021
v10.0.0

* tag 'v10.0.0': (40 commits)
  Release 10.0.0
  Testing the :skip option
  allow `object_changes_adapter` to use the default behavior
  Lint: Improve Metrics/AbcSize from 22 to 21
  Docs: which class attributes are public/private
  Docs: installation
  Docs: Update changelog and readme re: paper-trail-gem#1143
  Generator to update historic item_subtype entries (paper-trail-gem#1144)
  Testing joins, as recommended by Sean
  Add optional column: item_subtype
  Revert paper-trail-gem#1108 (lorint's STI fix)
  Lint: RSpec/EmptyLineAfterExampleGroup
  Update development dependencies
  Lint: RSpec/InstanceVariable in model_spec, ctn'd
  Code style re: errors
  Docs: Fix link to bug report
  Add association tracking removal exception
  Readme fix: caller.find {} rather than caller.first {}
  Do not require PT-AT
  Docs: Organizing the changelog for 10.0.0
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants